<template>
	<view class="user-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="false" color="#fff" title="我的"></uni-navbar></view>

		<!-- 群众端 -->
		<block v-if="userType != undefined && userType == 'qunzhong'">
			<view class="info-box">
				<view class="sub-box">
					<image class="sub-img" :src="$imagePreview(userInfo.imagePath)" mode="aspectFill"></image>
					<view class="sub-info">
						<view class="clamp">{{ userInfo.sysUser ? userInfo.sysUser.userName : '游客' }}</view>
						<view class="sub-node">
							<text class="txt">{{ userInfo.roleNames ? userInfo.roleNames[0] : '群众' }}</text>
						</view>
					</view>
				</view>
			</view>

			<view class="container">
				<u-cell-group class="link-list">
					<!-- <u-cell-item title="基本信息" @click="navTo('/pages/load/info')"><image slot="icon" class="list-icon" src="/static/img/icon_17.png" mode="widthFix"></image></u-cell-item> -->
					<u-cell-item title="小程序码" name="app" @click="navTo('/pages/user/app')">
						<image slot="icon" class="list-icon" src="/static/img/icon_19.png" mode="widthFix"></image>
					</u-cell-item>
					<u-cell-item title="退出登录" @click="loginOut" :borderBottom="false">
						<image slot="icon" class="list-icon" src="/static/img/icon_23.png" mode="widthFix"></image>
					</u-cell-item>
				</u-cell-group>
			</view>
		</block>
		<!-- 非群众端 -->
		<block v-if="userType != undefined && userType == 'contray-qunzhong'">
			<view class="info-box">
				<view class="sub-box">
					<image class="sub-img" @click="navTo('/pages/user/avatar')" :src="$imagePreview(userInfo.imagePath)" mode="aspectFill"></image>
					<view class="sub-info">
						<view class="clamp">{{ userInfo.sysUser.userName }}</view>
						<view class="sub-node">
							<text class="txt">{{ userInfo.roleNames[0] }}</text>
						</view>
					</view>
					<view class="sub-msg">
						<view class="msg-item" @click="navTo('/pagesB/system/list')">
							<view class="item-btm">{{ msgNum }}</view>
							<view class="item-top">我的消息</view>
						</view>
						<!-- <view class="msg-item" @click="navTo('/pagesB/notice/list')" v-if="$sysMenus('tzgg_top')">
							<view class="item-btm">{{ announcements }}</view>
							<view class="item-top">通知公告</view>
						</view> -->
						<view class="msg-item" @click="navTo('/pagesA/duties/index')" v-if="$sysMenus('perform')">
							<view class="item-btm">{{ num2 }}</view>
							<view class="item-top">履职账单</view>
						</view>
					</view>
				</view>
			</view>

			<view class="container">
				<u-cell-group class="link-list">
					<u-cell-item title="基本信息" @click="navTo('/pages/user/info?style=self')">
						<image slot="icon" class="list-icon" src="/static/img/icon_17.png" mode="widthFix"></image>
					</u-cell-item>
					<u-cell-item title="我的档案" @click="navTo('/pagesB/united/detail?style=self&id=' + userId)">
						<image slot="icon" class="list-icon" src="/static/img/icon_21.png" mode="widthFix"></image>
					</u-cell-item>
					<u-cell-item title="我的履职" v-if="$sysMenus('perform')" @click="dutiesTo('/pagesA/duties/self')">
						<image slot="icon" class="list-icon" src="/static/img/icon_18.png" mode="widthFix"></image>
					</u-cell-item>
					<u-cell-item title="小程序码" name="app" @click="navTo('/pages/user/app')">
						<image slot="icon" class="list-icon" src="/static/img/icon_19.png" mode="widthFix"></image>
					</u-cell-item>
					<u-cell-item title="退出登录" @click="loginOut" :borderBottom="false">
						<image slot="icon" class="list-icon" src="/static/img/icon_23.png" mode="widthFix"></image>
					</u-cell-item>
				</u-cell-group>
			</view>
		</block>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			userId: '',
			msgNum: 0,
			num2: 0,
			numAll: [],
			announcements: 0,
			userType: undefined //身份类型
		};
	},
	onLoad() {
		this.loadLogin();
		this.loadData();
		this.loadNum();
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				//群众
				if (this.userInfo.userId != undefined) {
					if (this.userInfo.roleCodes != undefined && this.userInfo.roleCodes.length > 0) {
						this.userType = this.userInfo.roleCodes[0];
						this.userId = this.userInfo.sysUser.id;
					}
				} else {
					this.userType = 'contray-qunzhong';
					this.clientCode = this.userInfo.sysUser.clientCode;
					this.roleCodes = this.userInfo.roleCodes.join(',');
					this.userId = this.userInfo.sysUser.id;
				}
			} else {
				this.$logout();
			}
		},
		loadData() {
			this.$request('/system/sysMsgPush/msgNum', {
				clientCode: this.clientCode,
				userId: this.userId
			}).then((res) => {
				this.msgNum = res.data.msgNum;
			});

			let data = {
				pageNum: 1,
				pageSize: 10,
				currentUserId: this.userId,
				roleCodes: this.roleCodes,
				clientCode: this.clientCode,
				readType: '',
				announcements: {
					dataType: '1'
				}
			};
			this.$request('/announcements/myList', data).then((res) => {
				this.announcements = res.data.total;
				console.log('myList：' + JSON.stringify(res));
			});
		},
		loginOut() {
			this.$store.commit('logout');
			uni.reLaunch({
				url: '/pages/login/index'
			});
		},
		loadNum() {
			let data = {
				userId: this.userId,
				clientCode: this.clientCode
			};
			this.$request('/perform/statistics/scoreCodeCount2', data).then((res) => {
				this.numAll = res.data;
				this.num2 = res.data.length || 0;
			});
		},
		dutiesTo(url) {
			uni.navigateTo({
				url: url + '?currentUserId=' + this.userId
			});
		},
		navTo(url) {
			uni.navigateTo({
				url: url
			});
		}
	}
};
</script>

<style lang="scss">
.link-list {
	margin-bottom: 30rpx;
	border-radius: 30rpx;
	overflow: hidden;
	background-color: #fff;

	.list-item {
		font-size: 28rpx;
		line-height: 72rpx;
	}

	.list-icon {
		width: 15px;
		margin-right: 16rpx;
	}
}
</style>
